/* Copyright (c) 2011 by Mani Brundha Kattamuri, Haritha Subramanyam
 *
 * Project Info:  http://code.google.com/p/andriod-travelapp-csc780/wiki/Design
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA.
 */
package com.example.TravelApp.search.quick;

import java.util.ArrayList;
import java.util.List;
import com.example.TravelApp.R;
import com.example.TravelApp.constants.MapConstants;
import com.example.TravelApp.search.common.GPlaceObjectActivity;
import com.example.TravelApp.search.common.PlaceObject;

import android.app.ListActivity;
import android.os.Bundle;
import android.os.Parcelable;
import android.content.Intent;
import android.graphics.Typeface;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

/**
 * This activity is called when the user selects a particular place among the
 * list of places. The layout is described in file
 * <code>res/layout/interest_layout.xml</code>. This activity displays details
 * of a place.
 * 
 * @author Haritha Subramanyam, Mani Brundha
 * 
 */

public class EachSubOptionDetailActivity extends ListActivity implements
		MapConstants {
	private static TextView heading;
	String place, intrest, time;
	private List<PlaceObject> list;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		Intent myIntent = getIntent();
		this.list = myIntent.getParcelableArrayListExtra("placesList");
		place = (String) getIntent().getCharSequenceExtra("Place");
		// TO prevent Null Pointers; proceeds only if the list is not empty
		if (this.list.isEmpty() != true) {
			setContentView(R.layout.interest_layout);
			heading = (TextView) findViewById(R.id.header);
			Typeface font = Typeface.createFromAsset(getAssets(),
					"Chantelli_Antiqua.ttf");
			heading.setTypeface(font);
			ArrayAdapter<PlaceObject> adapter = new GPlaceObjectActivity(this,
					this.list);

			setListAdapter(adapter);
			ListView listView = getListView();
			listView.setOnItemClickListener(new OnItemClickListener() {
				/**
				 * Implements an action listener for collecting place the user
				 * selected. Listens to the user's click and starts the map
				 * activity which shows the route to the selected place
				 */

				public void onItemClick(AdapterView<?> parent, View view,
						int position, long id) {
					Intent intent = new Intent(
							getBaseContext(),
							com.example.TravelApp.search.advanced.MapSrcToDestRouteActivity.class)
							.putParcelableArrayListExtra("placesList",
									(ArrayList<? extends Parcelable>) list)
							.putExtra("position", position)
							.putExtra("Place", place);
					startActivityForResult(intent, 0);
				}

			});
		} else {
			// If no is data available displays proper message on the screen
			setContentView(R.layout.no_results);
		}

	}

	/**
	 * Called whenever MapSrcToDestRouteActivity terminates.
	 */
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		if (resultCode == RESULT_OK) {
		}
	}

	/*
	 * Method onClick() will be called whenever the user presses the button in
	 * the MapSrcToDestRouteActivity.
	 */
	public void onClick(View v) {
		finish();
	}

}
